/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file  Can.c
 * @brief Semidrive. AUTOSAR 4.3.1 MCAL Can Driver.
 */
#ifdef __cplusplus
extern "C" {
#endif

#include "Can.h"
#include "Det.h"
#include "Can_IP.h"
#include "CanIf_Cbk.h"

/* Version and Check Begin */
/* Version Info Begin */
#define CAN_C_VENDOR_ID    0x8C
#define CAN_C_AR_RELEASE_MAJOR_VERSION    4
#define CAN_C_AR_RELEASE_MINOR_VERSION    3
#define CAN_C_AR_RELEASE_REVISION_VERSION 1
#define CAN_C_SW_MAJOR_VERSION    1
#define CAN_C_SW_MINOR_VERSION    0
#define CAN_C_SW_PATCH_VERSION    0
/* Version Info End */

/* Version Check Begin */
#if !defined(DISABLE_MCAL_ASR_VER_CHECK)
#if ((CAN_C_AR_RELEASE_MAJOR_VERSION != CAN_H_AR_RELEASE_MAJOR_VERSION)\
    || (CAN_C_AR_RELEASE_MINOR_VERSION != CAN_H_AR_RELEASE_MINOR_VERSION)\
    || (CAN_C_AR_RELEASE_REVISION_VERSION != CAN_H_AR_RELEASE_REVISION_VERSION))
#error "Opps, Can.c and Can.h AutoSAR version not match!"
#endif
#endif  /* !DISABLE_MCAL_ASR_VER_CHECK */
#if !defined(DISABLE_MCAL_SW_VER_CHECK)
#if ((CAN_C_SW_MAJOR_VERSION != CAN_H_SW_MAJOR_VERSION)\
    || (CAN_C_SW_MINOR_VERSION != CAN_H_SW_MINOR_VERSION)\
    || (CAN_C_SW_PATCH_VERSION != CAN_H_SW_PATCH_VERSION))
#error "Opps, Can.c and Can.h Software version not match!"
#endif
#endif  /* !DISABLE_MCAL_SW_VER_CHECK */
#if !defined(DISABLE_MCAL_ASR_VER_CHECK)
#if ((CAN_C_AR_RELEASE_MAJOR_VERSION != DET_H_AR_RELEASE_MAJOR_VERSION)\
    || (CAN_C_AR_RELEASE_MINOR_VERSION != DET_H_AR_RELEASE_MINOR_VERSION)\
    || (CAN_C_AR_RELEASE_REVISION_VERSION != DET_H_AR_RELEASE_REVISION_VERSION))
#error "Opps, Can.c and Det.h AutoSAR version not match!"
#endif
#endif  /* !DISABLE_MCAL_ASR_VER_CHECK */
#if !defined(DISABLE_MCAL_SW_VER_CHECK)
#if ((CAN_C_SW_MAJOR_VERSION != DET_H_SW_MAJOR_VERSION)\
    || (CAN_C_SW_MINOR_VERSION != DET_H_SW_MINOR_VERSION)\
    || (CAN_C_SW_PATCH_VERSION != DET_H_SW_PATCH_VERSION))
#error "Opps, Can.c and Det.h Software version not match!"
#endif
#endif  /* !DISABLE_MCAL_SW_VER_CHECK */
#if !defined(DISABLE_MCAL_ASR_VER_CHECK)
#if ((CAN_C_AR_RELEASE_MAJOR_VERSION != CAN_IP_H_AR_RELEASE_MAJOR_VERSION)\
    || (CAN_C_AR_RELEASE_MINOR_VERSION != CAN_IP_H_AR_RELEASE_MINOR_VERSION)\
    || (CAN_C_AR_RELEASE_REVISION_VERSION != CAN_IP_H_AR_RELEASE_REVISION_VERSION))
#error "Opps, Can.c and Can_IP.h AutoSAR version not match!"
#endif
#endif  /* !DISABLE_MCAL_ASR_VER_CHECK */
#if !defined(DISABLE_MCAL_SW_VER_CHECK)
#if ((CAN_C_SW_MAJOR_VERSION != CAN_IP_H_SW_MAJOR_VERSION)\
    || (CAN_C_SW_MINOR_VERSION != CAN_IP_H_SW_MINOR_VERSION)\
    || (CAN_C_SW_PATCH_VERSION != CAN_IP_H_SW_PATCH_VERSION))
#error "Opps, Can.c and Can_IP.h Software version not match!"
#endif
#endif  /* !DISABLE_MCAL_SW_VER_CHECK */
/* Version Check End */
/* Version and Check End */

/*########################Global variables########################*/

#define CAN_START_SEC_VAR_INIT_UNSPECIFIED
#include "Can_MemMap.h"

#define CAN_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "Can_MemMap.h"

#define CAN_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "Can_MemMap.h"


/*########################Internal variables########################*/

#define CAN_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "Can_MemMap.h"

#define CAN_START_SEC_CODE
#include "Can_MemMap.h"

/*########################Internal function declarations########################*/
#if (CAN_SET_BAUDRATE_API == STD_ON)
/**
 * @brief Check if the baud rate configuration ID is valid.
 */
static FUNC(Std_ReturnType, CAN_CODE) Can_ValidateBaudRateConfigID
(
    P2CONST(Can_ControllerConfigType, AUTOMATIC, CAN_APPL_DATA) ControllerConfig,
    VAR(uint16, AUTOMATIC) BaudRateConfigID
);
#endif

#if (!defined(AUTOSAR_VERSION_421)) && (!defined(AUTOSAR_VERSION_403))
static FUNC(Std_ReturnType, CAN_CODE) Can_StateArrayCheck
(
    VAR(uint8, AUTOMATIC) Controller
);
#endif/*!defined(AUTOSAR_VERSION_421)) && (!defined(AUTOSAR_VERSION_403)*/

/*########################Function implementations########################*/
#if (CAN_VERSION_INFO_API == STD_ON)
/**
 * @brief Get version information of CAN driver.
 * @param versioninfo Output version information.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_GetVersionInfo
(
    P2VAR(Std_VersionInfoType, AUTOMATIC, CAN_APPL_DATA) versioninfo
)
{
#if (CAN_DEV_ERROR_DETECT == STD_ON)

    if (versioninfo == NULL_PTR)
    {
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_GET_VERSION_INFO,
                              CAN_E_PARAM_POINTER);
    }
    else
    {
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
        versioninfo->vendorID = CAN_VENDOR_ID;
        versioninfo->moduleID = CAN_MODULE_ID;
        versioninfo->sw_major_version = CAN_SW_MAJOR_VERSION;
        versioninfo->sw_minor_version = CAN_SW_MINOR_VERSION;
        versioninfo->sw_patch_version = CAN_SW_PATCH_VERSION;
#if (CAN_DEV_ERROR_DETECT == STD_ON)
    }

#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
}
#endif /* CAN_VERSION_INFO_API == STD_ON */

/**
 * @brief Initialize all configured CAN controllers.
 * Initialize all configured CAN controllers.
 * CAN controller is configured in Can_Config.c.
 * The Can_Init() function must be called before using any other functions of the CAN module.
 * @param[in] Config Pointer to the CAN configuration.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_Init
(
    P2CONST(Can_ConfigType, AUTOMATIC, CAN_APPL_CONST) Config
)
{
    /* Variable for indexing configured controllers. */
    VAR(uint8, AUTOMATIC) ctrller_idx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    /* If the driver state is already ready, report an error. */
    if (coreHandlerPtr->Can_gCanDriverState == CAN_READY)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_INIT, CAN_E_TRANSITION);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    else
    {
        /* If the configuration pointer is null, report an error. */
        if (Config == NULL_PTR)
        {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
            (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_INIT,
                                  CAN_E_PARAM_POINTER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
        }
        else
        {
            /* Store the configuration pointer. */
            coreHandlerPtr->configPtr = Config;

            /* Initialize each controller. */
            /* PRQA S 2877 1 */
            for (ctrller_idx = 0U; ctrller_idx < CAN_VCAN_TOTAL_CONTROLLER_COUNT; ctrller_idx++)
            {
                if (ctrller_idx < CAN_CONTROLLER_COUNT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[ctrller_idx].coreId)
                    {
                        /* Store the default baud rate ID. */
                        coreHandlerPtr->Can_gu16CurBaudRateConfigId[ctrller_idx] =
                            coreHandlerPtr->configPtr->controllerConfig[ctrller_idx].defaultBaudRateId;

                        /* If the controller is active, try to initialize it. */
                        if (TRUE == coreHandlerPtr->configPtr->controllerConfig[ctrller_idx].controllerActive)
                        {

                            if (E_OK == Can_IP_InitController(ctrller_idx))
                            {
#if (defined(AUTOSAR_VERSION_421)) || (defined(AUTOSAR_VERSION_403))
                                /* Set the controller state to stopped. */
                                coreHandlerPtr->Can_gControllerState[ctrller_idx] = CAN_T_STOP;
#else
                                /* Set the controller state to stopped. */
                                coreHandlerPtr->Can_gControllerState[ctrller_idx] = CAN_CS_STOPPED;
#endif
                            }
                        }
                        else
                        {
                            /* Do Nothing */
                        }
                    }
                }

#if (VCAN_ENABLE == STD_ON)
                else
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[ctrller_idx -
                                        CAN_CONTROLLER_COUNT].coreId)
                    {
                        if (E_OK == VCan_IP_InitController(ctrller_idx))
                        {
#if (defined(AUTOSAR_VERSION_421)) || (defined(AUTOSAR_VERSION_403))
                            /* Set the controller state to stopped. */
                            coreHandlerPtr->Can_gControllerState[ctrller_idx] = CAN_T_STOP;
#else
                            /* Set the controller state to stopped. */
                            coreHandlerPtr->Can_gControllerState[ctrller_idx] = CAN_CS_STOPPED;
#endif
                        }
                    }
                }

#endif/*end of VCAN_ENABLE*/
            }

            /* Check if all controllers are initialized. */
            /* PRQA S 2877 1 */
            for (ctrller_idx = 0U; ctrller_idx < CAN_CONTROLLER_COUNT; ctrller_idx++)
            {
#if (defined(AUTOSAR_VERSION_421)) || (defined(AUTOSAR_VERSION_403))

                /* If the controller state is not uninitialized, set the driver state to ready. */
                if (CAN_T_UNINIT != coreHandlerPtr->Can_gControllerState[ctrller_idx])
                {
#else

                /* If the controller state is not uninitialized, set the driver state to ready. */
                if (CAN_CS_UNINIT != coreHandlerPtr->Can_gControllerState[ctrller_idx])
                {
#endif
                    coreHandlerPtr->Can_gCanDriverState = CAN_READY;
                }
                else
                {
                    /* Do Nothing */
                }
            }

        }
    }
}

/**
 * @brief De-initialize all configured controllers.
 * @details This function is responsible for de-initializing all configured
 *          CAN controllers. It will be called by the AUTOSAR RTE.
 * @param void no paramter.
 * @return none.
 */
#if (!defined(AUTOSAR_VERSION_421)) && (!defined(AUTOSAR_VERSION_403))
FUNC(void, CAN_CODE) Can_DeInit(void)
{
    /* Variable used for indexing configured controllers. */
    VAR(uint8, AUTOMATIC) ctrller_idx = 0U;
    /* Variable used to indicate whether any controller is in CAN_CS_STARTED state. */
    VAR(boolean, AUTOMATIC) can_busy = FALSE;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    /* Check if the CAN driver is in the ready state. If not, report an error. */
    if (coreHandlerPtr->Can_gCanDriverState != CAN_READY)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        /* Report an error. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_DEINIT, CAN_E_TRANSITION);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    else
    {
        /* Loop through all controllers. */
        /* PRQA S 2877 1 */
        for (ctrller_idx = 0U; ctrller_idx < CAN_CONTROLLER_COUNT;
                ctrller_idx++)
        {
            /* If the controller is currently started, set the flag and break the loop. */
            if (coreHandlerPtr->Can_gControllerState[ctrller_idx] == CAN_CS_STARTED)
            {
                can_busy = TRUE;
#if (CAN_DEV_ERROR_DETECT == STD_ON)
                /* Report an error. */
                (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_DEINIT, CAN_E_TRANSITION);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
                break;
            }
        }

        /* If no controllers are started, de-initialize all controllers. */
        if (can_busy == (boolean)FALSE)
        {
            /* Change the module state to CAN_UNINIT. */
            /* (CAN91009) The function Can_DeInit shall change the module state to
             * CAN_UNINIT before de-initializing all controllers inside the HW unit.
             */
            coreHandlerPtr->Can_gCanDriverState = CAN_UNINIT;

            /* Loop through all controllers and de-initialize them. */
            /* PRQA S 2877 1 */
            for (ctrller_idx = 0U; ctrller_idx < CAN_VCAN_TOTAL_CONTROLLER_COUNT; ctrller_idx++)
            {
                if (ctrller_idx < CAN_CONTROLLER_COUNT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[ctrller_idx].coreId)
                    {
                        Can_IP_DeInitController(ctrller_idx);
                    }
                }

#if (VCAN_ENABLE == STD_ON)
                else
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[ctrller_idx -
                                        CAN_CONTROLLER_COUNT].coreId)
                    {
                        VCan_IP_DeInitController(ctrller_idx);
                    }
                }

#endif/*end of VCAN_ENABLE*/

                coreHandlerPtr->Can_gControllerState[ctrller_idx] = CAN_CS_UNINIT;
            }
        }
    }
}
#endif

#if (CAN_SET_BAUDRATE_API == STD_ON)
/**
 * @brief Set baud rate of the controller.
 * @details This function is responsible for setting the baud rate of the
 *          specified CAN controller. It will be called by the AUTOSAR RTE.
 * @param Controller CAN controller ID.
 * @param BaudRateConfigID Baud rate configuration ID.
 * @return Baud rate setting result.
 *  @retval E_OK Set baud rate successfully.
 *  @retval E_NOT_OK Set baud rate failed.
 */
#if (defined(AUTOSAR_VERSION_421)) || (defined(AUTOSAR_VERSION_403))
FUNC(Std_ReturnType, CAN_CODE) Can_SetBaudrate
(
    VAR(uint8, AUTOMATIC) Controller,
    VAR(uint16, AUTOMATIC) BaudRateConfigID
)
{
    /* Function return value. */
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_NOT_OK;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    /* Check if the CAN driver is in the ready state. If not, report an error. */
    if (coreHandlerPtr->Can_gCanDriverState != CAN_READY)
    {
        /* Report an error if the CAN driver is not in the ready state. */
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_SET_BAUDRATE, CAN_E_UNINIT);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    else if (Controller >= CAN_CONTROLLER_COUNT)
    {
        /* Report an error if the controller ID is out of range. */
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_BAUDRATE,
                              CAN_E_PARAM_CONTROLLER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    else if (coreHandlerPtr->Can_gControllerState[Controller] != CAN_T_STOP)
    {
        /* Report an error if the controller is not in the stopped state. */
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_BAUDRATE,
                              CAN_E_TRANSITION);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    else if (E_OK != Can_ValidateBaudRateConfigID(
                 &coreHandlerPtr->configPtr->controllerConfig[Controller],
                 BaudRateConfigID))
    {
        /* Report an error if the baud rate configuration ID is invalid. */
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_BAUDRATE,
                              CAN_E_PARAM_BAUDRATE);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    else
    {
        /* Store the new baud rate configuration ID. */
        coreHandlerPtr->Can_gu16CurBaudRateConfigId[Controller] = BaudRateConfigID;

        if (coreId == coreHandlerPtr->configPtr->controllerConfig[Controller].coreId)
        {
            /* Initialize the controller again with the new baud rate configuration. */
            ret_result = Can_IP_InitController(Controller);
        }
    }

    return ret_result;
}
#else
/**
 * @brief Set baud rate of the controller.
 * @details This function is responsible for setting the baud rate of the
 *          specified CAN controller. It will be called by the AUTOSAR RTE.
 * @param Controller CAN controller ID.
 * @param BaudRateConfigID Baud rate configuration ID.
 * @return Baud rate setting result.
 *  @retval E_OK Set baud rate successfully.
 *  @retval E_NOT_OK Set baud rate failed.
 */
FUNC(Std_ReturnType, CAN_CODE) Can_SetBaudrate
(
    VAR(uint8, AUTOMATIC) Controller,
    VAR(uint16, AUTOMATIC) BaudRateConfigID
)
{
    /* Function return value. */
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_NOT_OK;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    /* Check if the controller ID is out of range. */
    if (Controller >= CAN_CONTROLLER_COUNT)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        /* Report an error if the controller ID is out of range. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_BAUDRATE,
                              CAN_E_PARAM_CONTROLLER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    /* Check if the controller is in an uninitialized state. */
    else if (coreHandlerPtr->Can_gControllerState[Controller] == CAN_CS_UNINIT)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        /* Report an error if the controller is in an uninitialized state. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_BAUDRATE,
                              CAN_E_UNINIT);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    /* Check if the controller is not in the stopped state. */
    else if (coreHandlerPtr->Can_gControllerState[Controller] != CAN_CS_STOPPED)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        /* Report an error if the controller is not in the stopped state. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_BAUDRATE,
                              CAN_E_TRANSITION);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    /* Check if the baud rate configuration ID is invalid. */
    else if (E_OK != Can_ValidateBaudRateConfigID(
                 &coreHandlerPtr->configPtr->controllerConfig[Controller],
                 BaudRateConfigID))
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        /* Report an error if the baud rate configuration ID is invalid. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_BAUDRATE,
                              CAN_E_PARAM_BAUDRATE);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    else
    {
        /* Store the new baud rate configuration ID. */
        coreHandlerPtr->Can_gu16CurBaudRateConfigId[Controller] = BaudRateConfigID;

        if (coreId == coreHandlerPtr->configPtr->controllerConfig[Controller].coreId)
        {
            /* Initialize the controller again with the new baud rate configuration. */
            ret_result = Can_IP_InitController(Controller);
        }
    }

    return ret_result;
}
#endif
#endif /* CAN_SET_BAUDRATE_API == STD_ON */

/**
 * @brief Trigger state transition of the CAN controller state machine.
 * @details This function is responsible for triggering state transition of the CAN controller state machine.
 *          It will be called by the AUTOSAR RTE.
 * @param Controller CAN controller ID.
 * @param Transition New CAN controller state.
 * @return State setting result.
 *  @retval E_OK State transimitted successfully.
 *  @retval E_NOT_OK State transimitted failed.
 */
#if (defined(AUTOSAR_VERSION_421)) || (defined(AUTOSAR_VERSION_403))
FUNC(Std_ReturnType, CAN_CODE) Can_SetControllerMode
(
    VAR(uint8, AUTOMATIC) Controller,
    VAR(Can_StateTransitionType, AUTOMATIC) Transition
)
{
    /* Return value. */
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_NOT_OK;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    /* Check if the CAN driver is not in the ready state. If not, report an error. */
    if (coreHandlerPtr->Can_gCanDriverState != CAN_READY)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        /* Report an error if the CAN driver is not in the ready state. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_SET_CONTROLLER_MODE, CAN_E_UNINIT);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    /* Check if the controller ID is out of range. If so, report an error. */
    else if (Controller >= CAN_VCAN_TOTAL_CONTROLLER_COUNT)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        /* Report an error if the controller ID is out of range. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_CONTROLLER_MODE,
                              CAN_E_PARAM_CONTROLLER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    /* Check if the transition is invalid. If so, report an error. */
    else if (Transition > CAN_T_WAKEUP)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        /* Report an error if the transition is invalid. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_CONTROLLER_MODE,
                              CAN_E_TRANSITION);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    else
    {
        switch (Transition)
        {
        case CAN_T_START:
            if (coreId == coreHandlerPtr->configPtr->controllerConfig[Controller].coreId)
            {
                ret_result = Can_IP_SetStartMode(Controller);
            }

            if (E_OK == ret_result)
            {
                coreHandlerPtr->Can_gControllerState[Controller] = CAN_T_START;
                CanIf_ControllerModeIndication(Controller, CANIF_CS_STARTED);
            }

            break;

        case CAN_T_SLEEP:

            /* Set the controller mode to sleep. */
            if (coreId == coreHandlerPtr->configPtr->controllerConfig[Controller].coreId)
            {
                ret_result = Can_IP_SetSleepMode(Controller);
            }

            if (E_OK == ret_result)
            {
                coreHandlerPtr->Can_gControllerState[Controller] = CAN_T_SLEEP;
                CanIf_ControllerModeIndication(Controller, CANIF_CS_SLEEP);
            }

            break;

        case CAN_T_STOP:

            /* Set the controller mode to stopped. */
            if (coreId == coreHandlerPtr->configPtr->controllerConfig[Controller].coreId)
            {
                ret_result = Can_IP_SetStopMode(Controller);
            }

            if (E_OK == ret_result)
            {
                coreHandlerPtr->Can_gControllerState[Controller] = CAN_T_STOP;
                CanIf_ControllerModeIndication(Controller, CANIF_CS_STOPPED);
            }

            break;

        case CAN_T_WAKEUP:

            /* Set the controller mode to stopped from sleep. */
            if (coreId == coreHandlerPtr->configPtr->controllerConfig[Controller].coreId)
            {
                ret_result = Can_IP_WakeUp(Controller);
            }

            if (E_OK == ret_result)
            {
                coreHandlerPtr->Can_gControllerState[Controller] = CAN_T_STOP;
                CanIf_ControllerModeIndication(Controller, CANIF_CS_STOPPED);
            }

            break;

        default:
            break;
        }
    }

    return ret_result;
}
#else
FUNC(Std_ReturnType, CAN_CODE) Can_SetControllerMode
(
    VAR(uint8, AUTOMATIC) Controller,
    VAR(Can_ControllerStateType, AUTOMATIC) Transition
)
{
    /* Return value. */
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_OK;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    /* Check if the CAN driver is ready. */
    if (coreHandlerPtr->Can_gCanDriverState != CAN_READY)
    {
        ret_result = E_NOT_OK;
        /* Report an error if the CAN driver is not in the ready state. */
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_SET_CONTROLLER_MODE, CAN_E_UNINIT);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    /* Check if the transition is invalid. */
    else if (Transition > CAN_CS_SLEEP)
    {
        ret_result = E_NOT_OK;
        /* Report an error if the transition is invalid. */
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_CONTROLLER_MODE,
                              CAN_E_TRANSITION);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }

    if (E_OK == ret_result)
    {
        ret_result = Can_StateArrayCheck(Controller);
    }

    if (E_OK == ret_result)
    {
        switch (Transition)
        {
        /* Start the controller. */
        case CAN_CS_STARTED:
        {
            if (Controller < CAN_CONTROLLER_COUNT)
            {
                if (coreId == coreHandlerPtr->configPtr->controllerConfig[Controller].coreId)
                {
                    ret_result = Can_IP_SetStartMode(Controller);
                }
                else
                {
                    ret_result = E_NOT_OK;
                }

                if (E_OK == ret_result)
                {
                    coreHandlerPtr->Can_gControllerState[Controller] = CAN_CS_STARTED;
                    CanIf_ControllerModeIndication(Controller, CAN_CS_STARTED);
                }

            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[VCAN_CONTROLLER_ARRAY_MAPPING(
                            Controller)].coreId)
                {
                    ret_result = VCan_IP_SetStartMode(Controller);
                }
                else
                {
                    ret_result = E_NOT_OK;
                }

                if (E_OK == ret_result)
                {
                    coreHandlerPtr->Can_gControllerState[VCAN_CONTROLLER_MIXED_MAPPING(Controller)] = CAN_CS_STARTED;
                    CanIf_ControllerModeIndication(Controller, CAN_CS_STARTED);
                }
            }

#endif/*end of VCAN_ENABLE*/



        }

        break;

        /* Enter sleep mode. */
        case CAN_CS_SLEEP:
        {

            if (Controller < CAN_CONTROLLER_COUNT)
            {
                if (coreId == coreHandlerPtr->configPtr->controllerConfig[Controller].coreId)
                {
                    ret_result = Can_IP_SetSleepMode(Controller);
                }
                else
                {
                    ret_result = E_NOT_OK;
                }

                if (E_OK == ret_result)
                {
                    coreHandlerPtr->Can_gControllerState[Controller] = CAN_CS_SLEEP;
                    CanIf_ControllerModeIndication(Controller, CAN_CS_SLEEP);
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[VCAN_CONTROLLER_ARRAY_MAPPING(
                            Controller)].coreId)
                {
                    ret_result = VCan_IP_SetSleepMode(Controller);
                }
                else
                {
                    ret_result = E_NOT_OK;
                }

                if (E_OK == ret_result)
                {
                    coreHandlerPtr->Can_gControllerState[VCAN_CONTROLLER_MIXED_MAPPING(Controller)] = CAN_CS_SLEEP;
                    CanIf_ControllerModeIndication(Controller, CAN_CS_SLEEP);
                }
            }

#endif/*end of VCAN_ENABLE*/
        }

        break;

        /* Stop the controller. */
        case CAN_CS_STOPPED:

        {
            if (Controller < CAN_CONTROLLER_COUNT)
            {
                if (coreId == coreHandlerPtr->configPtr->controllerConfig[Controller].coreId)
                {
                    ret_result = Can_IP_SetStopMode(Controller);
                }
                else
                {
                    ret_result = E_NOT_OK;
                }

                if (E_OK == ret_result)
                {
                    coreHandlerPtr->Can_gControllerState[Controller] = CAN_CS_STOPPED;
                    CanIf_ControllerModeIndication(Controller, CAN_CS_STOPPED);
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[VCAN_CONTROLLER_ARRAY_MAPPING(
                            Controller)].coreId)
                {
                    ret_result = VCan_IP_SetStopMode(Controller);
                }
                else
                {
                    ret_result = E_NOT_OK;
                }

                if (E_OK == ret_result)
                {
                    coreHandlerPtr->Can_gControllerState[VCAN_CONTROLLER_MIXED_MAPPING(Controller)] = CAN_CS_STOPPED;
                    CanIf_ControllerModeIndication(Controller, CAN_CS_STOPPED);
                }
            }

#endif/*end of VCAN_ENABLE*/


        }
        break;

        default:
            break;
        }
    }

    return ret_result;
}

#endif

/**
 * @brief Disable controller interrupts.
 * @param Controller Controller ID.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_DisableControllerInterrupts
(
    VAR(uint8, AUTOMATIC) Controller
)
{
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

#if (CAN_DEV_ERROR_DETECT == STD_ON)

    /* Check if the CAN driver is ready. */
    if (coreHandlerPtr->Can_gCanDriverState != CAN_READY)
    {
        /* Report an error if the CAN driver is not in the ready state. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_DISABLE_CONTROLLER_INTERRUPTS, CAN_E_UNINIT);
    }
    else if (((Controller >= CAN_CONTROLLER_COUNT)
              && (Controller < VCAN_NUMBER_OFFSET))
             || (Controller >= (VCAN_NUMBER_OFFSET + VCAN_CONTROLLER_COUNT)))
    {
        /* Report an error if the controller ID is out of range. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_DISABLE_CONTROLLER_INTERRUPTS, CAN_E_PARAM_CONTROLLER);
    }
    else
    {
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */

        if (Controller < CAN_CONTROLLER_COUNT)
        {
            /* Check if controller interrupts are already disabled. */
            if (coreHandlerPtr->Can_gu8ControllerIntsDisableCnt[Controller] == 0U)
            {
                if (coreId == coreHandlerPtr->configPtr->controllerConfig[Controller].coreId)
                {
                    /* Disable controller interrupts. */
                    Can_IP_DisableInterrupts(Controller);
                }
            }

            /* Increment the times that controller interrupts are disabled. */
            coreHandlerPtr->Can_gu8ControllerIntsDisableCnt[Controller]++;
        }

#if (VCAN_ENABLE == STD_ON)
        else
        {
            /* Check if controller interrupts are already disabled. */
            if (coreHandlerPtr->Can_gu8ControllerIntsDisableCnt[VCAN_CONTROLLER_MIXED_MAPPING(
                        Controller)] == 0U)
            {
                if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[VCAN_CONTROLLER_ARRAY_MAPPING(
                    Controller)].coreId)
                {
                    /* Disable controller interrupts. */
                    VCan_IP_DisableInterrupts(Controller);
                }
            }

            /* Increment the times that controller interrupts are disabled. */
            coreHandlerPtr->Can_gu8ControllerIntsDisableCnt[VCAN_CONTROLLER_MIXED_MAPPING(Controller)]++;
        }

#endif/*end of VCAN_ENABLE*/



#if (CAN_DEV_ERROR_DETECT == STD_ON)
    }

#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
}

/**
 * @brief Enable controller interrupts.
 * @param Controller Controller ID.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_EnableControllerInterrupts
(
    VAR(uint8, AUTOMATIC) Controller
)
{
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

#if (CAN_DEV_ERROR_DETECT == STD_ON)

    /* Check if the CAN driver is ready. */
    if (coreHandlerPtr->Can_gCanDriverState != CAN_READY)
    {
        /* Report an error if the CAN driver is not in the ready state. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_ENABLE_CONTROLLER_INTERRUPTS, CAN_E_UNINIT);
    }
    /* Check if the controller ID is out of range. */
    else if (((Controller >= CAN_CONTROLLER_COUNT)
              && (Controller < VCAN_NUMBER_OFFSET))
             || (Controller >= (VCAN_NUMBER_OFFSET + VCAN_CONTROLLER_COUNT)))
    {
        /* Report an error if the controller ID is out of range. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_ENABLE_CONTROLLER_INTERRUPTS, CAN_E_PARAM_CONTROLLER);
    }
    else
    {
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */

        /* (CAN208) The function Can_EnableControllerInterrupts shall perform no action
         * when Can_DisableControllerInterrupts has not been called before.
         */

        if (Controller < CAN_CONTROLLER_COUNT)
        {
            if (coreHandlerPtr->Can_gu8ControllerIntsDisableCnt[Controller] > 0U)
            {
                coreHandlerPtr->Can_gu8ControllerIntsDisableCnt[Controller]--;

                if (coreHandlerPtr->Can_gu8ControllerIntsDisableCnt[Controller] == 0U)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[Controller].coreId)
                    {
                        Can_IP_EnableInterrupts(Controller);
                    }
                }
            }
        }

#if (VCAN_ENABLE == STD_ON)
        else
        {
            if (coreHandlerPtr->Can_gu8ControllerIntsDisableCnt[VCAN_CONTROLLER_MIXED_MAPPING(Controller)] > 0U)
            {
                coreHandlerPtr->Can_gu8ControllerIntsDisableCnt[VCAN_CONTROLLER_MIXED_MAPPING(Controller)]--;

                if (coreHandlerPtr->Can_gu8ControllerIntsDisableCnt[VCAN_CONTROLLER_MIXED_MAPPING(
                            Controller)] == 0U)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[VCAN_CONTROLLER_ARRAY_MAPPING(
                        Controller)].coreId)
                    {
                        VCan_IP_EnableInterrupts(VCAN_CONTROLLER_MIXED_MAPPING(Controller));
                    }
                }
            }
        }

#endif/*end of VCAN_ENABLE*/

#if (CAN_DEV_ERROR_DETECT == STD_ON)
    }

#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
}

#if (CAN_CHECK_WAKEUP_API == STD_ON)
/**
 * @brief Check if a wakeup has occured for the controller.
 * @param Controller Controller ID.
 * @return API calling result.
 *  @retval E_OK Wakeup is detected.
 *  @retval E_NOT_OK Wakeup is not detected.
 */
FUNC(Std_ReturnType, CAN_CODE) Can_CheckWakeup
(
    VAR(uint8, AUTOMATIC) Controller
)
{
    /* Return value. */
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_OK;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    /* Check if the CAN driver is ready. If not, report an error. */
    if (coreHandlerPtr->Can_gCanDriverState != CAN_READY)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_CBK_CHECK_WAKEUP,
                              CAN_E_UNINIT);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
        ret_result = E_NOT_OK;
    }

    /* Check if the controller ID is out of range. If so, report an error. */
    if (((Controller >= CAN_CONTROLLER_COUNT)
            && (Controller < VCAN_NUMBER_OFFSET))
            || (Controller >= (VCAN_NUMBER_OFFSET + VCAN_CONTROLLER_COUNT)))
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_CBK_CHECK_WAKEUP,
                              CAN_E_PARAM_CONTROLLER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
        ret_result = E_NOT_OK;
    }

    if (E_OK == ret_result)
    {
        if (Controller < CAN_CONTROLLER_COUNT)
        {
            /* Check if the controller is in sleep mode. If the controller is in sleep mode, then the wake-up flag is set. */
            if (coreHandlerPtr->configPtr->controllerConfig[Controller].wakeupEnable == (boolean)TRUE)
            {
#if (defined(AUTOSAR_VERSION_421)) || (defined(AUTOSAR_VERSION_403))

                if (coreHandlerPtr->Can_gControllerState[Controller] != CAN_T_SLEEP)
                {
#else

                if (coreHandlerPtr->Can_gControllerState[Controller] != CAN_CS_SLEEP)
                {
#endif
                    ret_result = E_OK;
                }
            }
        }

#if (VCAN_ENABLE == STD_ON)
        else
        {
            /* Check if the controller is in sleep mode. If the controller is in sleep mode, then the wake-up flag is set. */
            if (coreHandlerPtr->configPtr->vcanControllerConfig[Controller - VCAN_NUMBER_OFFSET].wakeupEnable ==
                    (boolean)TRUE)
            {
#if (defined(AUTOSAR_VERSION_421)) || (defined(AUTOSAR_VERSION_403))

                if (coreHandlerPtr->Can_gControllerState[VCAN_CONTROLLER_MIXED_MAPPING(Controller)] != CAN_T_SLEEP)
                {
#else

                if (coreHandlerPtr->Can_gControllerState[VCAN_CONTROLLER_MIXED_MAPPING(Controller)] != CAN_CS_SLEEP)
                {
#endif
                    ret_result = E_OK;
                }
            }
        }

#endif/*end of VCAN_ENABLE*/
    }

    return ret_result;
}

#endif /* CAN_CHECK_WAKEUP_API == STD_ON */

/**
 * @brief Get error state of the controller.
 * @param ControllerId Controller ID.
 * @param ErrorStatePtr Ouput error state.
 * @return API calling result.
 *  @retval E_OK Call API successfully.
 *  @retval E_NOT_OK Call API failed.
 */
FUNC(Std_ReturnType, CAN_CODE) Can_GetControllerErrorState
(
    VAR(uint8, AUTOMATIC) ControllerId,
    P2VAR(Can_ErrorStateType, AUTOMATIC, CAN_APPL_DATA) ErrorStatePtr
)
{
    /* Return result. */
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_NOT_OK;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    /* Check if the CAN driver is ready. If not, report an error. */
    if (coreHandlerPtr->Can_gCanDriverState != CAN_READY)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_GETCONTROLLERERRORSTATE,
                              CAN_E_UNINIT);
#endif
    }
    /* Check if the controller ID is out of range. If yes, report an error. */
    else if (ControllerId >= CAN_CONTROLLER_COUNT)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_GETCONTROLLERERRORSTATE,
                              CAN_E_PARAM_CONTROLLER);
#endif
    }
    /* Check if the error state pointer is NULL. If yes, report an error. */
    else if (ErrorStatePtr == NULL_PTR)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_GETCONTROLLERERRORSTATE,
                              CAN_E_PARAM_POINTER);
#endif
    }
    else
    {
        if (coreId == coreHandlerPtr->configPtr->controllerConfig[ControllerId].coreId)
        {
            /* Get error state from IP layer and store it in the output parameter. */
            *ErrorStatePtr = Can_IP_GetErrorState(ControllerId);
            /* Return E_OK to indicate successful API execution. */
            ret_result = E_OK;
        }
        else
        {
            ret_result = E_NOT_OK;
        }
    }

    return ret_result;
}

/**
 * @brief Get the current state of the controller.
 * @param Controller Controller ID.
 * @param ControllerModePtr Output the current state.
 * @return API calling result.
 *  @retval E_OK Call API successfully.
 *  @retval E_NOT_OK Call API failed.
 */
#if (defined(AUTOSAR_VERSION_421)) || (defined(AUTOSAR_VERSION_403))
FUNC(Std_ReturnType, CAN_CODE) Can_GetControllerMode
(
    VAR(uint8, AUTOMATIC) Controller,
    P2VAR(Can_StateTransitionType, AUTOMATIC, CAN_APPL_DATA) ControllerModePtr
)
#else
FUNC(Std_ReturnType, CAN_CODE) Can_GetControllerMode
(
    VAR(uint8, AUTOMATIC) Controller,
    P2VAR(Can_ControllerStateType, AUTOMATIC, CAN_APPL_DATA) ControllerModePtr
)
#endif
{
    /* Return result. */
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_OK;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    /* Check if the CAN driver is in the ready state. If not, report an error. */
    if (coreHandlerPtr->Can_gCanDriverState != CAN_READY)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_GETCONTROLLERMODE,
                              CAN_E_UNINIT);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
        ret_result = E_NOT_OK;
    }

    /* Check if the controller ID is out of range. If yes, report an error. */
    if (((Controller >= CAN_CONTROLLER_COUNT)
            && (Controller < VCAN_NUMBER_OFFSET))
            || (Controller >= (VCAN_NUMBER_OFFSET + VCAN_CONTROLLER_COUNT)))
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_GETCONTROLLERMODE,
                              CAN_E_PARAM_CONTROLLER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
        ret_result = E_NOT_OK;
    }
    /* Check if the controller mode pointer is NULL. If yes, report an error. */
    else if (ControllerModePtr == NULL_PTR)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_GETCONTROLLERMODE,
                              CAN_E_PARAM_POINTER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
        ret_result = E_NOT_OK;
    }

    if (E_OK == ret_result)
    {
        if (Controller < CAN_CONTROLLER_COUNT)
        {
            /* Copy the current controller state to the output parameter. */
            *ControllerModePtr = coreHandlerPtr->Can_gControllerState[Controller];
            /* Return E_OK to indicate successful API execution. */
        }
        else
        {
            /* Copy the current controller state to the output parameter. */
            *ControllerModePtr = coreHandlerPtr->Can_gControllerState[VCAN_CONTROLLER_MIXED_MAPPING(
                                     Controller)];
            /* Return E_OK to indicate successful API execution. */

        }

        ret_result = E_OK;
    }

    return ret_result;
}
#define CAN_STOP_SEC_CODE
#include "Can_MemMap.h"

#define CAN_START_SEC_CODE_FAST
#include "Can_MemMap.h"
/**
 * @brief Transmit a CAN message.
 * @param Hth Hardware-transmit handle.
 * @param PduInfo Pointer to SDU user memory, data length and identifier.
 * @return API calling result.
 *  @retval E_OK Write CAN MB successfully.
 *  @retval E_NOT_OK Write CAN MB failed.
 */
FUNC(Std_ReturnType, CAN_CODE) Can_Write
(
    VAR(Can_HwHandleType, AUTOMATIC) Hth,
    P2CONST(Can_PduType, AUTOMATIC, CAN_APPL_DATA) PduInfo
)
{
    /* Return result. */
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_NOT_OK;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    /* Check if the CAN driver is in the ready state. If not, report an error. */
    if (coreHandlerPtr->Can_gCanDriverState != CAN_READY)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_WRITE, CAN_E_UNINIT);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    /* Check if the hardware transmit handle is out of range. If yes, report an error. */
    else if (Hth >= CAN_HOH_MAX)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_WRITE,
                              CAN_E_PARAM_HANDLE);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    /* Check if the PDU information pointer is NULL. If yes, report an error. */
    else if (PduInfo == NULL_PTR)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_WRITE,
                              CAN_E_PARAM_POINTER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }

#if (CAN_TRIGGER_TRANSMIT_EN == STD_OFF)
    /* Check if the SDU pointer is NULL. If yes, report an error. */
    else if (PduInfo->sdu == NULL_PTR)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_WRITE,
                              CAN_E_PARAM_POINTER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }

#endif /* CAN_TRIGGER_TRANSMIT_EN == STD_ON */
    else
    {
        ret_result = Can_IP_Write(Hth, PduInfo);
    }

    return ret_result;
}

/**
 * @brief Polling of Tx confirmation.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Write(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].txProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        Can_IP_TxPolling(controllerIdx, 0U, FALSE);
#else
                        Can_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].txProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        VCan_IP_TxPolling(controllerIdx, 0U, FALSE);
#else
                        VCan_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}

/**
 * @brief Polling of Rx indication.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Read(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].rxProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        Can_IP_RxPolling(controllerIdx, 0U, FALSE);
#else
                        Can_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].rxProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        VCan_IP_RxPolling(controllerIdx, 0U, FALSE);
#else
                        VCan_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}

#define CAN_STOP_SEC_CODE_FAST
#include "Can_MemMap.h"

#define CAN_START_SEC_CODE
#include "Can_MemMap.h"
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
#if (CAN_MAINFUNCTION_RW_PERIOD_0 != STD_OFF)
/**
 * @brief Polling of Tx confirmation at period 0.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Write_0(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].txProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        Can_IP_TxPolling(controllerIdx, 0U, TRUE);
#else
                        Can_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].txProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        VCan_IP_TxPolling(controllerIdx, 0U, TRUE);
#else
                        VCan_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_0 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_1 != STD_OFF)
/**
 * @brief Polling of Tx confirmation at period 1.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Write_1(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT; controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].txProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        Can_IP_TxPolling(controllerIdx, 1U, TRUE);
#else
                        Can_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].txProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        VCan_IP_TxPolling(controllerIdx, 1U, TRUE);
#else
                        VCan_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_1 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_2 != STD_OFF)
/**
 * @brief Polling of Tx confirmation at period 2.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Write_2(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].txProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        Can_IP_TxPolling(controllerIdx, 2U, TRUE);
#else
                        Can_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].txProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        VCan_IP_TxPolling(controllerIdx, 2U, TRUE);
#else
                        VCan_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_2 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_3 != STD_OFF)
/**
 * @brief Polling of Tx confirmation at period 3.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Write_3(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].txProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        Can_IP_TxPolling(controllerIdx, 3U, TRUE);
#else
                        Can_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].txProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        VCan_IP_TxPolling(controllerIdx, 3U, TRUE);
#else
                        VCan_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_3 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_4 != STD_OFF)
/**
 * @brief Polling of Tx confirmation at period 4.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Write_4(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].txProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        Can_IP_TxPolling(controllerIdx, 4U, TRUE);
#else
                        Can_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].txProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        VCan_IP_TxPolling(controllerIdx, 4U, TRUE);
#else
                        VCan_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_4 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_5 != STD_OFF)
/**
 * @brief Polling of Tx confirmation at period 5.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Write_5(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].txProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        Can_IP_TxPolling(controllerIdx, 5U, TRUE);
#else
                        Can_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].txProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        VCan_IP_TxPolling(controllerIdx, 5U, TRUE);
#else
                        VCan_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_5 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_6 != STD_OFF)
/**
 * @brief Polling of Tx confirmation at period 6.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Write_6(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].txProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        Can_IP_TxPolling(controllerIdx, 6U, TRUE);
#else
                        Can_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].txProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        VCan_IP_TxPolling(controllerIdx, 6U, TRUE);
#else
                        VCan_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_6 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_7 != STD_OFF)
/**
 * @brief Polling of Tx confirmation at period 7.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Write_7(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].txProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        Can_IP_TxPolling(controllerIdx, 7U, TRUE);
#else
                        Can_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].txProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        VCan_IP_TxPolling(controllerIdx, 7U, TRUE);
#else
                        VCan_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_7 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_0 != STD_OFF)
/**
 * @brief Polling of Tx confirmation at period 8.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Write_8(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].txProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        Can_IP_TxPolling(controllerIdx, 8U, TRUE);
#else
                        Can_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].txProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        VCan_IP_TxPolling(controllerIdx, 8U, TRUE);
#else
                        VCan_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_8 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_0 != STD_OFF)
/**
 * @brief Polling of Tx confirmation at period 9.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Write_9(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].txProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        Can_IP_TxPolling(controllerIdx, 9U, TRUE);
#else
                        Can_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].txProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_WRITE_PERIOD == STD_ON)
                        VCan_IP_TxPolling(controllerIdx, 9U, TRUE);
#else
                        VCan_IP_TxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_9 != STD_OFF */
#endif /* CAN_MULTIPLE_WRITE_PERIOD == STD_ON */

#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
#if (CAN_MAINFUNCTION_RW_PERIOD_0 != STD_OFF)
/**
 * @brief Polling of Rx indication at period 0.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Read_0(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].rxProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        Can_IP_RxPolling(controllerIdx, 0U, TRUE);
#else
                        Can_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].rxProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        VCan_IP_RxPolling(controllerIdx, 0U, TRUE);
#else
                        VCan_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_0 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_1 != STD_OFF)
/**
 * @brief Polling of Rx indication at period 1.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Read_1(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT; controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].rxProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        Can_IP_RxPolling(controllerIdx, 1U, TRUE);
#else
                        Can_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].rxProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        VCan_IP_RxPolling(controllerIdx, 1U, TRUE);
#else
                        VCan_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_1 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_2 != STD_OFF)
/**
 * @brief Polling of Rx indication at period 2.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Read_2(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].rxProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        Can_IP_RxPolling(controllerIdx, 2U, TRUE);
#else
                        Can_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].rxProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        VCan_IP_RxPolling(controllerIdx, 2U, TRUE);
#else
                        VCan_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_2 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_3 != STD_OFF)
/**
 * @brief Polling of Rx indication at period 3.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Read_3(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].rxProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        Can_IP_RxPolling(controllerIdx, 3U, TRUE);
#else
                        Can_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].rxProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        VCan_IP_RxPolling(controllerIdx, 3U, TRUE);
#else
                        VCan_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_3 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_4 != STD_OFF)
/**
 * @brief Polling of Rx indication at period 4.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Read_4(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].rxProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        Can_IP_RxPolling(controllerIdx, 4U, TRUE);
#else
                        Can_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].rxProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        VCan_IP_RxPolling(controllerIdx, 4U, TRUE);
#else
                        VCan_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_4 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_5 != STD_OFF)
/**
 * @brief Polling of Rx indication at period 5.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Read_5(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].rxProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        Can_IP_RxPolling(controllerIdx, 5U, TRUE);
#else
                        Can_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].rxProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        VCan_IP_RxPolling(controllerIdx, 5U, TRUE);
#else
                        VCan_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_5 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_6 != STD_OFF)
/**
 * @brief Polling of Rx indication at period 6.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Read_6(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].rxProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        Can_IP_RxPolling(controllerIdx, 6U, TRUE);
#else
                        Can_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].rxProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        VCan_IP_RxPolling(controllerIdx, 6U, TRUE);
#else
                        VCan_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_6 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_7 != STD_OFF)
/**
 * @brief Polling of Rx indication at period 7.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Read_7(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].rxProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        Can_IP_RxPolling(controllerIdx, 7U, TRUE);
#else
                        Can_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].rxProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        VCan_IP_RxPolling(controllerIdx, 7U, TRUE);
#else
                        VCan_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_7 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_8 != STD_OFF)
/**
 * @brief Polling of Rx indication at period 8.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Read_8(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].rxProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        Can_IP_RxPolling(controllerIdx, 8U, TRUE);
#else
                        Can_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].rxProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        VCan_IP_RxPolling(controllerIdx, 8U, TRUE);
#else
                        VCan_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_8 != STD_OFF */

#if (CAN_MAINFUNCTION_RW_PERIOD_9 != STD_OFF)
/**
 * @brief Polling of Rx indication at period 9.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Read_9(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_VCAN_TOTAL_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (controllerIdx < CAN_CONTROLLER_COUNT)
            {
                if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].rxProcType != INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        Can_IP_RxPolling(controllerIdx, 9U, TRUE);
#else
                        Can_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#if (VCAN_ENABLE == STD_ON)
            else
            {
                if (coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                      CAN_CONTROLLER_COUNT].rxProcType !=
                        INTERRUPT)
                {
                    if (coreId == coreHandlerPtr->configPtr->vcanControllerConfig[controllerIdx -
                                          CAN_CONTROLLER_COUNT].coreId)
                    {
#if (CAN_MULTIPLE_READ_PERIOD == STD_ON)
                        VCan_IP_RxPolling(controllerIdx, 9U, TRUE);
#else
                        VCan_IP_RxPolling(controllerIdx);
#endif
                    }
                }
            }

#endif/*end of VCAN_ENABLE*/
        }
    }
}
#endif /* CAN_MAINFUNCTION_RW_PERIOD_9 != STD_OFF */
#endif /* CAN_MULTIPLE_READ_PERIOD == STD_ON */

/**
 * @brief Polling of bus-off event.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_BusOff(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* Iterate through each controller. */
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_CONTROLLER_COUNT;
                controllerIdx++)
        {
            /* Check if the bus-off processing mode is polling. */
            if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].busoffProcType == POLLING)
            {
                if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                {
                    /* Perform polling of the bus-off event. */
                    Can_IP_BusOffPolling(controllerIdx);
                }
            }
        }
    }
}

/**
 * @brief Polling of wake-up event.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Wakeup(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* Iterate through each controller to perform polling of wake-up event. */
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_CONTROLLER_COUNT;
                controllerIdx++)
        {
            if (coreHandlerPtr->configPtr->controllerConfig[controllerIdx].wakeupProcType == POLLING)
            {
                if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
                {
                    /* Perform polling of the wake-up event. */
                    Can_IP_WakeUpPolling(controllerIdx);
                }
            }
        }
    }
}

/**
 * @brief Polling of controller mode transitions.
 * @param none.
 * @return none.
 */
FUNC(void, CAN_CODE) Can_MainFunction_Mode(void)
{
    /* Variable used for indexing controllers. */
    VAR(uint8, AUTOMATIC) controllerIdx = 0U;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    /* Check if the CAN configuration is valid. */
    if (NULL_PTR != coreHandlerPtr->configPtr)
    {
        /* Iterate through each controller to check the mode transition. */
        /* PRQA S 2877 1 */
        for (controllerIdx = 0U; controllerIdx < CAN_CONTROLLER_COUNT; controllerIdx++)
        {
            if (coreId == coreHandlerPtr->configPtr->controllerConfig[controllerIdx].coreId)
            {
                /* Perform polling of the controller mode transition. */
                Can_IP_ControllerModePolling(controllerIdx);
            }
        }
    }
}

#if defined(AUTOSAR_VERSION_431)
Std_ReturnType Can_GetControllerRxErrorCounter (
    uint8 ControllerId,
    uint8 *RxErrorCounterPtr
)
{
    /* Return result. */
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_NOT_OK;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (ControllerId >= CAN_CONTROLLER_COUNT)
    {
        /* Report an error if the controller ID is out of range. */
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_GET_CONTROLLER_RX_ERROR_COUNTER,
                              CAN_E_PARAM_CONTROLLER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    /* Check if the controller is in an uninitialized state. */
    else if (coreHandlerPtr->Can_gControllerState[ControllerId] == CAN_CS_UNINIT)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        /* Report an error if the controller is in an uninitialized state. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_GET_CONTROLLER_RX_ERROR_COUNTER,
                              CAN_E_UNINIT);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    /* Check if the rx error counter pointer is NULL. If yes, report an error. */
    else if (RxErrorCounterPtr == NULL_PTR)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_GET_CONTROLLER_RX_ERROR_COUNTER,
                              CAN_E_PARAM_POINTER);
#endif
    }
    else
    {
        if (coreId == coreHandlerPtr->configPtr->controllerConfig[ControllerId].coreId)
        {
            /* Get rx error counter from IP layer and store it in the output parameter. */
            *RxErrorCounterPtr = Can_IP_GetControllerRxErrorCounter(ControllerId);
            /* Return E_OK to indicate successful API execution. */
            ret_result = E_OK;
        }
        else
        {
            ret_result = E_NOT_OK;
        }
    }

    return ret_result;
}

Std_ReturnType Can_GetControllerTxErrorCounter (
    uint8 ControllerId,
    uint8 *TxErrorCounterPtr
)
{
    /* Return result. */
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_NOT_OK;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    if (ControllerId >= CAN_CONTROLLER_COUNT)
    {
        /* Report an error if the controller ID is out of range. */
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_GET_CONTROLLER_TX_ERROR_COUNTER,
                              CAN_E_PARAM_CONTROLLER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    /* Check if the controller is in an uninitialized state. */
    else if (coreHandlerPtr->Can_gControllerState[ControllerId] == CAN_CS_UNINIT)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        /* Report an error if the controller is in an uninitialized state. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_GET_CONTROLLER_TX_ERROR_COUNTER,
                              CAN_E_UNINIT);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
    }
    /* Check if the tx error counter pointer is NULL. If yes, report an error. */
    else if (TxErrorCounterPtr == NULL_PTR)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_GET_CONTROLLER_TX_ERROR_COUNTER,
                              CAN_E_PARAM_POINTER);
#endif
    }
    else
    {
        if (coreId == coreHandlerPtr->configPtr->controllerConfig[ControllerId].coreId)
        {
            /* Get tx error counter from IP layer and store it in the output parameter. */
            *TxErrorCounterPtr = Can_IP_GetControllerTxErrorCounter(ControllerId);
            /* Return E_OK to indicate successful API execution. */
            ret_result = E_OK;
        }
        else
        {
            ret_result = E_NOT_OK;
        }
    }

    return ret_result;
}
#endif/*#if defined(AUTOSAR_VERSION_431)*/

/*########################Internal Function implementations########################*/
#if (CAN_SET_BAUDRATE_API == STD_ON)
/**
 * @brief Validate the baud rate configuration ID.
 * @param ControllerConfig Pointer to the configuration of a controller.
 * @param BaudRateConfigID Baud rate configuration ID.
 * @return API calling result.
 *  @retval E_OK Baud rate configuration ID is valid.
 *  @retval E_NOT_OK Baud rate configuration ID is invalid.
 */
static FUNC(Std_ReturnType, CAN_CODE) Can_ValidateBaudRateConfigID
(
    P2CONST(Can_ControllerConfigType, AUTOMATIC, CAN_APPL_DATA) ControllerConfig,
    VAR(uint16, AUTOMATIC) BaudRateConfigID
)
{
    /* Return value. */
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_NOT_OK;
    /* Variable used for indexing baud rate configuration. */
    VAR(uint16, AUTOMATIC) baudRateCfgIdx = 0U;

    /* Iterate through each baud rate configuration to check if the given baud rate configuration ID is valid. */
    for (baudRateCfgIdx = 0; baudRateCfgIdx < ControllerConfig->baudRateConfigCount; baudRateCfgIdx++)
    {
        if (ControllerConfig->baudRateConfig[baudRateCfgIdx].baudRateConfigId == BaudRateConfigID)
        {
            /* If the given baud rate configuration ID is valid, set the return value to E_OK. */
            ret_result = E_OK;
            break;
        }
    }

    return ret_result;
}
#endif

#if (!defined(AUTOSAR_VERSION_421)) && (!defined(AUTOSAR_VERSION_403))
static FUNC(Std_ReturnType, CAN_CODE) Can_StateArrayCheck
(
    VAR(uint8, AUTOMATIC) Controller
)
{
    /* Return value. */
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_OK;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];

    /* Check if the controller ID is out of range. */
    if (((Controller >= CAN_CONTROLLER_COUNT)
            && (Controller < VCAN_NUMBER_OFFSET))
            || (Controller >= (VCAN_NUMBER_OFFSET + VCAN_CONTROLLER_COUNT)))
    {
        /* Report an error if the controller ID is out of range. */
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_CONTROLLER_MODE,
                              CAN_E_PARAM_CONTROLLER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
        ret_result = E_NOT_OK;
    }

    /* Check if the controller is in an uninitialized state. */
    if ((E_OK == ret_result) && (Controller < CAN_CONTROLLER_COUNT))
    {
        if (CAN_CS_UNINIT == coreHandlerPtr->Can_gControllerState[Controller])
        {
            /* Report an error if the controller is in an uninitialized state. */
#if (CAN_DEV_ERROR_DETECT == STD_ON)
            (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_CONTROLLER_MODE,
                                  CAN_E_UNINIT);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
            ret_result = E_NOT_OK;
        }
    }

    /* Check if the controller is in an uninitialized state. */
    if ((E_OK == ret_result) && (Controller >= VCAN_NUMBER_OFFSET))
    {
        if (CAN_CS_UNINIT == coreHandlerPtr->Can_gControllerState[VCAN_CONTROLLER_MIXED_MAPPING(
                    Controller)])
        {
            /* Report an error if the controller is in an uninitialized state. */
#if (CAN_DEV_ERROR_DETECT == STD_ON)
            (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE, CAN_SID_SET_CONTROLLER_MODE,
                                  CAN_E_UNINIT);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
            ret_result = E_NOT_OK;
        }
    }

    return ret_result;
}
#endif/*!defined(AUTOSAR_VERSION_421)) && (!defined(AUTOSAR_VERSION_403)*/

#if (VCAN_ENABLE == STD_ON)
VCan_TxRxAbnormalNumType* Can_Vcan_TxRxFifoGetAbnormalNum(uint8 Controller)
{
    VAR(Std_ReturnType, AUTOMATIC) ret_result = E_OK;
    uint8 coreId = Can_Ip_GetCoreID();
    Can_HandlerConfigType *coreHandlerPtr = Can_HandlerPtr[coreId];
    VCan_TxRxAbnormalNumType *abnormalNum = NULL_PTR;

    if (Controller < VCAN_NUMBER_OFFSET)
    {
        /* Report an error if the controller ID is out of range. */
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_VCAN_TX_RX_FIFO_GET_ABNORMAL_NUM,
                              CAN_E_PARAM_CONTROLLER);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
        ret_result = E_NOT_OK;
    }
    /* Check if the controller is in an uninitialized state. */
    else if (coreHandlerPtr->Can_gCanDriverState != CAN_READY)
    {
#if (CAN_DEV_ERROR_DETECT == STD_ON)
        /* Report an error if the controller is in an uninitialized state. */
        (void)Det_ReportError((uint16)CAN_MODULE_ID, (uint8)CAN_INSTANCE,
                              CAN_SID_VCAN_TX_RX_FIFO_GET_ABNORMAL_NUM,
                              CAN_E_UNINIT);
#endif /* CAN_DEV_ERROR_DETECT == STD_ON */
        ret_result = E_NOT_OK;
    }

    if (ret_result == E_OK)
    {
        abnormalNum = &(coreHandlerPtr->g_VCanTxRxAbnormalNum[Controller - VCAN_NUMBER_OFFSET]);
    }

    return abnormalNum;
}
#endif/*end of VCAN_ENABLE*/

#define CAN_STOP_SEC_CODE
#include "Can_MemMap.h"

#ifdef __cplusplus
}

#endif
